package com.foreknow.elm.controller;

import com.foreknow.elm.po.User;
import com.foreknow.elm.service.UserService;
import com.foreknow.elm.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

public class UserController {
    public Object getUserByIdByPass(HttpServletRequest request){
        String userid = request.getParameter("userId");
        String password = request.getParameter("password");
        UserService userService = new UserServiceImpl();
        User user = userService.sgetUserByIdByPass(userid,password);
        return user;
    }

    public Object getUserById(HttpServletRequest request){
        String userId = request.getParameter("userId");
        UserService userService = new UserServiceImpl();
        int isRight = userService.sgetUserById(userId);
        return isRight;
    }

    public Object saveUser(HttpServletRequest request){
        User user = new User();
        String userid = request.getParameter("userId");
        String password = request.getParameter("password");
        String username =  request.getParameter("userName");
        Integer usersex = Integer.valueOf(request.getParameter("userSex"));
        user.setUserId(userid);
        user.setPassword(password);
        user.setUserName(username);
        user.setUserSex(usersex);
        UserService userService = new UserServiceImpl();
        int isRight = userService.ssaveUser(user);
        return isRight;
    }
}
